package com.daiqee.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import com.daiqee.controller.support.CommonsController;
import com.daiqee.pojo.ProcurementContract;
import com.daiqee.service.impl.ProcurementConractService;

/**
 * 采购合同
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V2.1
 * @author RichardTang 
 * @date: 2018年5月7日 下午5:54:29
 * @package com.daiqee.handler
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Controller
@RequestMapping("procurement/procurement-contract")
public class ProcurementContractController extends CommonsController<ProcurementContract>{

	@Autowired
	private ProcurementConractService contractService;
	
	/**
	 * 采购合同上传
	 * @param contractImages
	 * 				表单提交过来的图片对象
	 * @param id
	 * 			对应的数据的uuid
	 * @return
	 */
    @RequestMapping(value = "/contractUpload",method=RequestMethod.POST)
    public ResponseEntity<Map<String, Object>> uploadByContract(MultipartFile contractImages,String id){
    	Map<String, Object> map = new HashMap<String, Object>();
    	try {
	        // 上传图片
	        if (contractImages != null && !(contractImages.isEmpty())) {
	            isNormalFinish = contractService.saveContractImg(contractImages,id);
	            if(isNormalFinish) {
	            	map.put("success", "上传成功!");
	            	return ResponseEntity.ok(map);
	            }
	        }
    	}catch (Exception e) {
    		logger.error(e.getMessage());
    		map.put("error", "服务器繁忙!");
    		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(map);
		}
    	map.put("error", "上传失败!");
    	return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(map);
    }
}
